<?php
/**
 * created by zzy
 * date: 2017/11/21 10:39
 */

namespace App\Http\Admin\System\Controllers;

use App\Eloquent\Ygt\Dictionary;
use Framework\BaseClass\Http\Admin\Controller;

class DictionaryController extends Controller
{
    public function index(){}
    public function lists(){
        if (request()->isMethod('post')) {

            $where          = [];
            $lists          = Dictionary::getList( $where );
            return $lists->toJson();
        }
        return $this->view('lists' );
    }
    public function edit(){

        $params             = $this->requestJson();
        $id                 = isset($params['id']) ? $params['id'] : 0;
        $value              = isset($params['value']) ? $params['value'] : '';
        if(!$value)
        {
            return $this->ajaxFail( '名称必填' );
        }
        $data               = ['value'=>$value];
        if( $id ){
            $where          = ['id'=>$id];
            $result         = Dictionary::updateOneData( $where, $data );
        } else {
            $result         = Dictionary::insertOneData( $data );
        }
        if( $result ){
            return $this->ajaxSuccess( '成功' );
        } else {
            return $this->ajaxFail( '失败' );
        }
    }
    public function delete()
    {
        $id                 = request('id',0);
        if( $id ){
            $where          = ['id'=>$id];
            $delResult      = Dictionary::del($where);
            if( $delResult ){
                return $this->ajaxSuccess( '成功' );
            } else {
                return $this->ajaxFail( '失败' );
            }
        } else {
            return $this->ajaxFail('失败3');
        }
    }
}
